//
//  Copyright (C) 2010 Vadim Ushakov
// 
//  This program is free software; you can redistribute it and/or modify it
//  under the terms of the GNU General Public License as published by the Free
//  Software Foundation; either version 2 of the License, or (at your option)
//  any later version.
// 
//  This program is distributed in the hope that it will be useful, but
//  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
//  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
//  for more details.
//  
//  You should have received a copy of the GNU General Public License along
//  with this program; if not, write to the Free Software Foundation, Inc.,
//  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//

#ifndef _KERNELSPINLOCK_H
#define _KERNELSPINLOCK_H

#include "kernelProcessorLevel.h"

typedef struct _kernelSpinLock
{
	int id;
	int recursive;
	int level;
} kernelSpinLock;


int kernelSpinLockAcquire(volatile kernelSpinLock* lck); // LEVEL: <= lck->level
int kernelSpinLockRelease(volatile kernelSpinLock* lck, int level); // LEVEL: == lck->level

int kernelSpinLockSetRecursive(volatile kernelSpinLock* lck);
int kernelSpinLockSetProcessorLevel(volatile kernelSpinLock* lck, int level);

int kernelInitializeSpinLock(void);

#define SPIN_LOCK_DECL(lck, level) kernelSpinLock lck = {0, 0, level}
#define SPIN_LOCK_DECL_RECURSIVE(lck, level) kernelSpinLock lck = {0, 1, level}

#endif/*_KERNELSPINLOCK_H*/


